package neusoft.yuejian_11.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import neusoft.yuejian_11.adapter.VideoListAdapter;
import neusoft.yuejian_11.base.BaseActivity;
import neusoft.yuejian_11.bean.VideoBean;
import neusoft.yuejian_11.listener.RetrofitListener;
import neusoft.yuejian_11.model.ClubModel;
import neusoft.yuejian_11.R;

public class VideoListActivity extends BaseActivity implements RetrofitListener {
    protected Context context;
    private int clubId;
    private String clubName;
    private String clubPic;
    private TextView textViewClubName;
    private ImageView imageViewClub;
    private VideoListAdapter adapter;
    private RecyclerView recyclerView;
    private ImageButton imageButtonBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_list);
        initViews();//初始化
        initEvents();//点击事件处理
        showData();//传参
        initData();//网络获取
    }

    private void initViews() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        textViewClubName = (TextView) findViewById(R.id.textView_club_name);
        imageViewClub = (ImageView) findViewById(R.id.imageViewClub);
        imageButtonBack = (ImageButton) findViewById(R.id.imageButtom_back);
    }

    private void initEvents() {
        imageButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private void showData() {
        clubId = getIntent().getIntExtra("c_id",-1);
        clubName = getIntent().getStringExtra("c_name");
        textViewClubName.setText(clubName);
        clubPic = getIntent().getStringExtra("c_pic");
        Picasso.with(context)
                .load(clubPic)
                .placeholder(R.drawable.ic_club)
                .error(R.drawable.ic_noclub)
                .into(imageViewClub);
    }

    private void initData() {
        ClubModel clubModel = new ClubModel();
        clubModel.videoList(String.valueOf(clubId),this);
    }

    @Override
    public void onSuccess(Object o, int flag) {
        List<VideoBean> videoBeanList = (List<VideoBean>) o;
        adapter = new VideoListAdapter(VideoListActivity.this,videoBeanList);
        LinearLayoutManager layoutManager = new LinearLayoutManager(VideoListActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }

    @Override
    public void onFail() {

    }

}
